package com.example.module.custom.fragment;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.alibaba.android.arouter.launcher.ARouter;
import com.alibaba.fastjson.JSON;
import com.bigkoo.pickerview.builder.OptionsPickerBuilder;
import com.bigkoo.pickerview.listener.OnOptionsSelectChangeListener;
import com.bigkoo.pickerview.listener.OnOptionsSelectListener;
import com.bigkoo.pickerview.view.OptionsPickerView;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.example.module.custom.R;
import com.example.module.custom.R2;
import com.example.module.custom.adapter.SearchAdapter;
import com.example.module.custom.bean.IdBean;
import com.example.module.custom.bean.PQCDetailsBean;
import com.example.module.custom.http.HTTPURL;
import com.example.module.custom.ui.PQCAddActivity;
import com.example.module.custom.ui.PQCListActivity;
import com.example.module.custom.utils.SoftKeyboardUtil;
import com.example.module.custom.utils.ToastUtil;
import com.example.module.custom.view.WheelView;
import com.example.zhouwei.library.CustomPopWindow;
import com.google.gson.Gson;
import com.lzy.okgo.model.HttpParams;
import com.nand.library.base.base.BaseFragment;
import com.nand.library.base.bean.ResponseBean;
import com.nand.library.base.http.MyCallback;
import com.nand.library.base.http.OkGoUtils;
import com.nand.library.zxing.activity.CaptureActivity;
import com.nand.library.zxing.activity.CodeUtils;

import java.net.URL;
import java.sql.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @name BlockDemo
 * @class name：com.nand.module.function.fragment
 * @classdescribe 新增pqc基本信息(复查, 查看详情)
 * @anthor ljp
 * @time 2020/1/7 10:55
 */
public class PQCInforFragment extends BaseFragment {
    private static int FEATURES = 1;//功能选项（1、新增pqc，2、复查pqc 3、查看详情【不可操作】）
    public static final int CODE_WORK_PROGRESS_BATCH = 1001;//在制品批次
    public static final int CODE_MATERIAL_ID = 1001;//材料夹具ID
    @BindView(R2.id.tv_production_stage)
    TextView tvProductionStage;
    @BindView(R2.id.linear_production_stage)
    LinearLayout linearProductionStage;
    @BindView(R2.id.tv_process)
    TextView tvProcess;
    @BindView(R2.id.linear_process)
    LinearLayout linearProcess;
    @BindView(R2.id.et_device_id)
    TextView etDeviceId;
    //@BindView(R2.id.image_device_id)
    //ImageView imageDeviceId;
    @BindView(R2.id.tv_device_name)
    TextView tvDeviceName;
    @BindView(R2.id.et_item_num)
    TextView etItemNum;
    //  @BindView(R2.id.image_item_num)
    // ImageView imageItemNum;
    @BindView(R2.id.tv_item_name)
    TextView tvItemName;
    // @BindView(R2.id.tv_product_num)
    // TextView tvProductNum;
    //  @BindView(R2.id.linear_product_num)
    //  LinearLayout linearProductNum;
    @BindView(R2.id.tv_inspection_type)
    TextView tvInspectionType;
    @BindView(R2.id.linear_inspection_type)
    LinearLayout linearInspectionType;
    /*@BindView(R2.id.tv_production_batch)
    TextView tvProductionBatch;
    @BindView(R2.id.linear_production_batch)
    LinearLayout linearProductionBatch;
    @BindView(R2.id.et_work_in_progress)
    EditText etWorkInProgress;
    @BindView(R2.id.image_work_in_progress)
    ImageView imageWorkInProgress;*/
    @BindView(R2.id.et_work_in_progress_batch)
    EditText etWorkInProgressBatch;
    @BindView(R2.id.image_work_in_progress_batch)
    ImageView imageWorkInProgressBatch;
    @BindView(R2.id.et_material_id)
    EditText etMaterialId;
    @BindView(R2.id.image_material_id)
    ImageView imageMaterialId;
    @BindView(R2.id.image_more_type)
    ImageView imageTypeMore;

    /* @BindView(R2.id.et_product_id)
     EditText etProductId;
     @BindView(R2.id.image_product)
     ImageView imageProduct;*/
    @BindView(R2.id.tv_test_result)
    TextView tvTestResult;
    @BindView(R2.id.et_disqualified)
    EditText etDisqualified;
    @BindView(R2.id.tv_review_result)
    TextView tvReviewResult;
    @BindView(R2.id.view_line)
    View viewLine;
    @BindView(R2.id.linear_disqualified)
    LinearLayout linearDisqualified;
    @BindView(R2.id.linear_review)
    LinearLayout linearReview;
    @BindView(R2.id.btn_submit_continue)
    Button btnSubmitContinue;
    @BindView(R2.id.btn_submit)
    Button btnSubmit;
    @BindView(R2.id.linear_btn)
    LinearLayout linearBtn;
    @BindView(R2.id.tv_product_number)
    TextView tvProductNumber;
    private String TAG = "PQCInforFragment";
    private List<String> options1Items;
    private WheelView mWheelview;
    private TextView mTvConfirm;
    private TextView mTvCancel;
    private CustomPopWindow mCustomPopWindow;
    private String oid;
    private static PQCDetailsBean pqcDetailsBeanTest;
    private static PQCInforFragment fragment;
    private String testJson;
    private PQCDetailsBean pqcDetailsBeanAdd;
    private PQCDetailsBean pqcDetailsBeanDetail;
    private SearchAdapter mAdapter;
    private OptionsPickerView typePicker;

    public static PQCInforFragment newInstance(int flag, String oid) {
        PQCInforFragment fragment = new PQCInforFragment();
        Bundle bundle = new Bundle();
        bundle.putInt("FEATURES", flag);
        bundle.putString("oid", oid);
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_pqc_infor;
    }

    @Override
    protected void initView(View view) {
        ButterKnife.bind(this, view);
        FEATURES = getArguments().getInt("FEATURES");
        oid = getArguments().getString("oid");
        //根据flag判断当前页面
        featuresJud();
        //edittext监听
        initViewEdit();
        typePicker = new OptionsPickerBuilder(mContext, new OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int options2, int options3, View v) {
                gzlbID = options1;
                tvInspectionType.setText(options1Items.get(options1));
            }
        }).setOptionsSelectChangeListener(new OnOptionsSelectChangeListener() {
            @Override
            public void onOptionsSelectChanged(int options1, int options2, int options3) {
                if (options1 !=  gzlbID) {
                    gzlbID = options1;
                    typePicker.setSelectOptions(options1);
                }
            }
        }).setSubmitText("确定")//确定按钮文字
                .setCancelText("取消")//取消按钮文字
                .setSubCalSize(16)//确定和取消文字大小
                .setSubmitColor(Color.GRAY)//确定按钮文字颜色
                .setCancelColor(Color.GRAY)//取消按钮文字颜色
                .setContentTextSize(25)//滚轮文字大小
                .setCyclic(false, false, false)//循环与否
                .build();
    }
    /**
     * @author ljp
     * @time 11:00
     * @describe 功能判断页面 //功能选项（1、新增pqc，2、复查pqc 3、查看详情【不可操作】）
     */
    private void featuresJud() {

        switch (FEATURES) {
            case 1:
                String[] stringArray = getResources().getStringArray(R.array.text_type);
                options1Items = Arrays.asList(stringArray);
                break;
            case 2:
                setHttpData(HTTPURL.PQC_DETAILS);
                etWorkInProgressBatch.setBackground(null);
                btnSubmitContinue.setVisibility(View.GONE);
                imageMaterialId.setVisibility(View.GONE);
                imageWorkInProgressBatch.setVisibility(View.GONE);
                linearDisqualified.setVisibility(View.VISIBLE);
                linearReview.setVisibility(View.VISIBLE);
                etMaterialId.setBackground(null);
                imageTypeMore.setVisibility(View.GONE);
                viewLine.setVisibility(View.VISIBLE);
                setEdit();
                setRight();
                break;
            case 3:
                setHttpData(HTTPURL.PQC_DETAILS);
                etWorkInProgressBatch.setBackground(null);
                linearBtn.setVisibility(View.GONE);
                imageMaterialId.setVisibility(View.GONE);
                imageWorkInProgressBatch.setVisibility(View.GONE);
                linearDisqualified.setVisibility(View.VISIBLE);
                linearReview.setVisibility(View.VISIBLE);
                etMaterialId.setBackground(null);
                etDisqualified.setBackground(null);
                imageTypeMore.setVisibility(View.GONE);
                etDisqualified.setFocusable(false);
                etDisqualified.setFocusableInTouchMode(false);
                etDisqualified.setCursorVisible(false);
                viewLine.setVisibility(View.VISIBLE);
                setEdit();
                setRight();
                etDisqualified.setGravity(Gravity.RIGHT);
                break;
        }

    }
    /**
     *  @author ljp
     *  @time   10:36
     *  @describe 详情页面右对齐
     */
    private void setRight(){
        tvProductionStage.setGravity(Gravity.RIGHT);
        tvProcess.setGravity(Gravity.RIGHT);
        etDeviceId.setGravity(Gravity.RIGHT);
        tvDeviceName.setGravity(Gravity.RIGHT);
        etItemNum.setGravity(Gravity.RIGHT);
        tvItemName.setGravity(Gravity.RIGHT);
        tvProductNumber.setGravity(Gravity.RIGHT);
        etWorkInProgressBatch.setGravity(Gravity.RIGHT);
        tvTestResult.setGravity(Gravity.RIGHT);
        tvReviewResult.setGravity(Gravity.RIGHT);
        tvInspectionType.setGravity(Gravity.RIGHT);
    }
    /**
     * @author ljp
     * @time 17:38
     * @describe 在制品编码输入框监听
     */
    private void initViewEdit() {
        etWorkInProgressBatch.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                if ((actionId == 0 || actionId == 3) && event != null) {
                    String search = etWorkInProgressBatch.getText().toString().trim();
                    Log.i(TAG, "onEditorAction: ---search-----" + search);
                    etWorkInProgressBatch.setText(search);
                    etWorkInProgressBatch.setSelection(search.length());
                    codeHttpData(search,1);
                    SoftKeyboardUtil.hideKeyboard(getActivity());
                    return true;
                }
                return false;
            }
        });
        etMaterialId.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                if ((actionId == 0 || actionId == 3) && event != null) {
                    String search = etMaterialId.getText().toString().trim();
                    Log.i(TAG, "onEditorAction: ---search-----" + search);
                    etMaterialId.setText(search);
                    etWorkInProgressBatch.setSelection(search.length());
                    codeHttpData(search,2);
                    SoftKeyboardUtil.hideKeyboard(getActivity());
                    return true;
                }
                return false;
            }
        });
        etWorkInProgressBatch.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void afterTextChanged(Editable editable) {

            }
        });
    }
    /**
     * @author ljp
     * @time 17:44
     * @describe 新建pqc 根据编码查询数据
     */
    private void codeHttpData(String value,int type) {
        if (TextUtils.isEmpty(value)) {
            ToastUtil.showShortToast("请输入或扫描在制品编码",mContext);
            return;
        }
        HttpParams httpParams = new HttpParams();
        httpParams.put("winNode", value);
        httpParams.put("type", type);//1查询制品编码，2载具编码
        OkGoUtils.getInstance().post(getActivity(), HTTPURL.PQC_ADD_CODE_SELECT, httpParams, 1, true, new MyCallback() {
            @Override
            public void onSuccess(ResponseBean response, int id) {
                if (response.getCode() == 200) {
                    String data = response.getDataInfo().toString();
                    Log.i(TAG, "onSuccess: -----" + response.getDataInfo().toString());
                    PQCDetailsBean pqcDetailsBean = new Gson().fromJson(data, PQCDetailsBean.class);
                    if (pqcDetailsBean != null) {
                        setPqcBean(pqcDetailsBean);
                        PQCTestFragment2.getInstance().setPqcDetailsBeans(pqcDetailsBean,gzlbID);
                        initAddData(pqcDetailsBean);
                    }else {
                        ToastUtil.showShortToast("没有查询数据",mContext);
                    }
                }
            }

            @Override
            public void onError(Throwable e, int id) {

            }
        });
    }
    /**
     * @author ljp
     * @time 13:14
     * @describe 设置不可点击 不可编辑
     */
    private void setEdit() {
        etMaterialId.setFocusable(false);
        etMaterialId.setFocusableInTouchMode(false);
        etMaterialId.setCursorVisible(false);
        etWorkInProgressBatch.setFocusable(false);
        etWorkInProgressBatch.setFocusableInTouchMode(false);
        etWorkInProgressBatch.setCursorVisible(false);
        linearInspectionType.setClickable(false);
    }
    /**
     * @author ljp
     * @time 16:12
     * @describe 新增pqc 根据编码赋值
     */
    private void initAddData(PQCDetailsBean pqcDetailsBean) {
        pqcDetailsBeanAdd = pqcDetailsBean;
        tvInspectionType.setText(options1Items.get(0));
        tvProductionStage.setText(pqcDetailsBean.getProductionStageName());
        tvProcess.setText(pqcDetailsBean.getProcessContent());
        etDeviceId.setText(pqcDetailsBean.getEquipId());
        tvDeviceName.setText(pqcDetailsBean.getEquipName());
        tvItemName.setText(pqcDetailsBean.getMaterialName());
        etItemNum.setText(pqcDetailsBean.getMaterialId());
        //etWorkInProgressBatch.setText(pqcDetailsBean.getWipBatch());
        etDisqualified.setText(pqcDetailsBean.getUnqualiFiedHandle());
        tvProductNumber.setText(pqcDetailsBean.getProductModel());
        pqcDetailsBean.setCheckType(gzlbID);
        // ((PQCAddActivity) getActivity()).initDetailsData(pqcDetailsBean);
    }
    /**
     * @author ljp
     * @time 16:12
     * @describe 详情&复查页面控件赋值
     */
    private void initDetailsData(PQCDetailsBean pqcDetailsBean) {
        Log.i(TAG, "initDetailsData: ----initDetailsData-------" + pqcDetailsBean.toString());
        tvProductionStage.setText(pqcDetailsBean.getProductionStageName());
        tvProcess.setText(pqcDetailsBean.getProcessContent());
        etDeviceId.setText(pqcDetailsBean.getEquipId());
        tvDeviceName.setText(pqcDetailsBean.getEquipName());
        etItemNum.setText(pqcDetailsBean.getPartId());
        tvItemName.setText(pqcDetailsBean.getPartName());
        tvProductNumber.setText(pqcDetailsBean.getProductModel());
        etWorkInProgressBatch.setText(pqcDetailsBean.getWipBatch());
        tvTestResult.setText(pqcDetailsBean.getCheckResult() == 0 ? "合格" : "不合格");//检查结果 0合格1不合格
        // tvReviewResult.setText(pqcDetailsBean.getReviewResult() == 0 ? "合格" : "不合格");//检查结果 0合格1不合格
        if (FEATURES == 3 ) {
            if(pqcDetailsBean.getCheckResult() == 0){
                linearDisqualified.setVisibility(View.GONE);
                linearReview.setVisibility(View.GONE);
                viewLine.setVisibility(View.GONE);
            }else {
                linearReview.setVisibility(View.VISIBLE);
                linearDisqualified.setVisibility(View.VISIBLE);
                etDisqualified.setText(pqcDetailsBean.getUnqualiFiedHandle());
                if (pqcDetailsBean.getReviewResult() == 0) {//复查结果 0合格1不合格 2未复查
                    tvReviewResult.setText("合格");
                } else if (pqcDetailsBean.getReviewResult() == 1) {
                    tvReviewResult.setText("不合格");
                } else {
                    tvReviewResult.setText("未复查");
                }
            }

        }else if(FEATURES == 2){
            etDisqualified.setText(pqcDetailsBean.getUnqualiFiedHandle());
            if (pqcDetailsBean.getReviewResult() == 0) {//复查结果 0合格1不合格 2未复查
                tvReviewResult.setText("合格");
            } else if (pqcDetailsBean.getReviewResult() == 1) {
                tvReviewResult.setText("不合格");
            } else {
                tvReviewResult.setText("未复查");
            }
        }
        switch (pqcDetailsBean.getCheckType()) {//检验类型0首检1巡检2自检3末捡
            case 0:
                tvInspectionType.setText("首检");
                break;
            case 1:
                tvInspectionType.setText("巡检");
                break;
            case 2:
                tvInspectionType.setText("自检");
                break;
            case 3:
                tvInspectionType.setText("末捡");
                break;
        }

    }


    /**
     * @author ljp
     * @time 16:05
     * @describe 网络请求(详情、复查页面数据查询)
     */
    private void setHttpData(String url) {
        HttpParams httpParams = new HttpParams();
        httpParams.put("oid", oid);
        OkGoUtils.getInstance().post(getActivity(), url, httpParams, 1, true, new MyCallback() {
            @Override
            public void onSuccess(ResponseBean response, int id) {
                // Log.i(TAG, "onSuccess: -----" + response.getCode());
                if (response.getCode() == 200) {
                    String data = response.getDataInfo().toString();
                    Log.i(TAG, "onSuccess: -----" + response.getDataInfo().toString());
                    pqcDetailsBeanDetail = new Gson().fromJson(data, PQCDetailsBean.class);
                    if (pqcDetailsBeanDetail != null) {
                        initDetailsData(pqcDetailsBeanDetail);
                        if (FEATURES == 2)
                            setPqcBean(pqcDetailsBeanDetail);
                    }
                }
            }

            @Override
            public void onError(Throwable e, int id) {

            }
        });

    }



    @SuppressLint("InvalidR2Usage")
    @OnClick({R2.id.linear_process, R2.id.linear_inspection_type,
           /* R2.id.linear_production_batch, R2.id.image_product,
            R2.id.image_device_id,R2.id.linear_product_num,R2.id.image_work_in_progress,
            R2.id.image_item_num,*/
            R2.id.linear_production_stage,
            R2.id.image_work_in_progress_batch,
            R2.id.image_material_id, R2.id.btn_submit_continue, R2.id.btn_submit})
    public void onViewClicked(View view) {
        Log.i(TAG, "onViewClicked: -------");
        int id = view.getId();
        if (id == R.id.linear_inspection_type) {//检验类型
            Log.i(TAG, "onViewClicked: -----------");
            //initPop1(options1Items, tvInspectionType);
            typePicker.setPicker(options1Items);
            typePicker.show();
        } else if (id == R.id.image_material_id) {//载具编码
            Intent intent = new Intent(mContext, CaptureActivity.class);
            startActivityForResult(intent, CODE_MATERIAL_ID);
        } else if (id == R.id.image_work_in_progress_batch) {//在制品批次扫描
            Intent intent = new Intent(mContext, CaptureActivity.class);
            startActivityForResult(intent, CODE_WORK_PROGRESS_BATCH);
        } else if (id == R.id.btn_submit_continue) {//提交并继续
            if (!TextUtils.isEmpty(etWorkInProgressBatch.getText().toString().trim())) {
                judePQCAddBtn(true);
            } else {
                ToastUtil.showShortToast("请输入或扫描在制品编码", mContext);
            }
            Log.i(TAG, "onViewClicked: ---etWorkInProgressBatch---" + etWorkInProgressBatch.getText().toString());
        } else if (id == R.id.btn_submit) {//提交
            if (!TextUtils.isEmpty(etWorkInProgressBatch.getText().toString().trim())) {
                judePQCAddBtn(false);
            } else {
                ToastUtil.showShortToast("请输入或扫描在制品编码", mContext);
            }
            Log.i(TAG, "onViewClicked: ---etWorkInProgressBatch---" + etWorkInProgressBatch.getText().toString());
        }
    }
    /**
     * @author ljp
     * @time 11:32
     * @describe 弹出列表选择popu
     */
    private void initPop1(final List<IdBean> lists, final TextView textView) {
        //创建并显示popWindow
        View view = View.inflate(mContext, R.layout.popup_item_list, null);
        mCustomPopWindow = new CustomPopWindow.PopupWindowBuilder(mContext)
                .setView(view)
                .enableBackgroundDark(true) //弹出popWindow时，背景是否变暗
                .setBgDarkAlpha(0.7f) // 控制亮度
                .setAnimationStyle(R.style.pop_anim_style)
                .create()
                .showAtLocation(tvTestResult, Gravity.BOTTOM, 0, 0);
        mWheelview = (WheelView) view.findViewById(R.id.wheel_view_list);
        mTvConfirm = view.findViewById(R.id.tv_confirm);
        mTvCancel = view.findViewById(R.id.tv_cancel);
        mWheelview.setOffset(1);
        mWheelview.setItems(lists);
        mWheelview.setSeletion(gzlbID);
        mWheelview.setOnWheelViewListener(new WheelView.OnWheelViewListener() {
            @Override
            public void onSelected(int selectedIndex, IdBean ite) {
                // item = ite.getType();
                // gzlbID = ite.getId();
                gzlbID = ite.getId();

            }
        });
        mTvConfirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String seletedItem = mWheelview.getSeletedItem();
                textView.setText(seletedItem);
                //PQCTestFragment2.getInstance().setPqcDetailsBeans(pqcDetailsBeanAdd,gzlbID);
              //  if (0 == mWheelview.getSeletedItemId())
               //     gzlbID = 1;
                //Log.i(TAG, "onClick: -----gzlbID------"+gzlbID);
                PQCTestFragment2.getInstance().setPqcDetailsBeans(pqcDetailsBeanAdd,gzlbID);
                mCustomPopWindow.dissmiss();
            }
        });

        mTvCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mCustomPopWindow.dissmiss();
            }
        });
    }
    /**
     * @author ljp
     * @time 19:29
     * @describe pqc 提交判断
     */
    private void judePQCAddBtn(final boolean isContinue) {
        if (FEATURES == 1) {//新增
            String testResult = tvTestResult.getText().toString();
            if (TextUtils.isEmpty(testResult)) {
                ToastUtil.showShortToast("请选择检验结果", mContext);
            } else {
                String trim = etMaterialId.getText().toString().trim();
                HttpParams httpParams = new HttpParams();
                httpParams.put("productionStage", pqcDetailsBeanAdd.getProductionStage());
                httpParams.put("fQmProcessContentOid", pqcDetailsBeanAdd.getProcessOid());
                httpParams.put("fEqDetailOid", pqcDetailsBeanAdd.getEquipOid());
                httpParams.put("fMmMaterialOid", pqcDetailsBeanAdd.getMaterialOid());
                httpParams.put("productModel", pqcDetailsBeanAdd.getProductModel());
                httpParams.put("checkType", gzlbID);
                httpParams.put("wipBatch", etWorkInProgressBatch.getText().toString().trim());
                if (!TextUtils.isEmpty(trim)) {
                    httpParams.put("binID", trim);
                }
                httpParams.put("fUserCreator", 1);
                httpParams.put("checkResult", tvTestResult.getText().toString().equals("合格") ? 0 : 1);
                httpParams.put("checkDetail", testJson);
                OkGoUtils.getInstance().post(getActivity(), HTTPURL.PQC_ADD_CODE_ADD, httpParams, 3, true, new MyCallback() {
                    @Override
                    public void onSuccess(ResponseBean response, int id) {
                        if (response.getCode() == 200) {
                            ToastUtil.showShortToast("提交成功", mContext);
                            if (isContinue) {//如果继续，清空所有数据，重新添加
                                clearAddData();
                            } else {//
                                // ARouter.getInstance().build("/custom/PQCList").withInt("type", 1).navigation();
                                ((Activity) mContext).finish();
                            }
                        } else {
                            ToastUtil.showShortToast(response.getMsg(), mContext);
                        }
                    }
                    @Override
                    public void onError(Throwable e, int id) {

                    }
                });
            }
        } else {//复查
            String testResult = tvReviewResult.getText().toString();
            String trim = etDisqualified.getText().toString().trim();
            if (TextUtils.isEmpty(testResult) || testResult.equals("未复查")) {
                ToastUtil.showShortToast("请选择检验结果", mContext);
            } else if (testResult.equals("不合格") && TextUtils.isEmpty(trim)) {
                ToastUtil.showShortToast("请输入处理措施", mContext);
            } else {
                if (TextUtils.isEmpty(testJson)) {
                    Gson gson = new Gson();
                    testJson = gson.toJson(pqcDetailsBeanDetail.getDetailList());
                }
                HttpParams httpParams = new HttpParams();
                httpParams.put("fUserUpdater", 1);
                httpParams.put("oid", pqcDetailsBeanDetail.getOid());
                httpParams.put("OptimisticLockField", pqcDetailsBeanDetail.getOptimisticLockField());
                //  httpParams.put("checkResult", testResult.equals("合格")?0:1);
                httpParams.put("reviewResult", testResult.equals("合格") ? 0 : 1);
                httpParams.put("unqualiFiedHandle", etDisqualified.getText().toString().trim());
                httpParams.put("checkDetail", testJson);
                Log.i(TAG, "judePQCAddBtn: -----" + httpParams.toString());
                OkGoUtils.getInstance().post(getActivity(), HTTPURL.PQC_ADD_CODE_REVIEW, httpParams, 3, true, new MyCallback() {
                    @Override
                    public void onSuccess(ResponseBean response, int id) {
                        Log.i(TAG, "onSuccess: -----response-----" + response.toString());
                        //ToastUtil.showShortToast(response.getMsg(),mContext);
                        if (response.getCode() == 200) {
                            ToastUtil.showShortToast("提交成功", mContext);
                            //  ARouter.getInstance().build("/custom/PQCList").withInt("type", 2).navigation();
                            ((Activity) mContext).finish();
                        } else {
                            ToastUtil.showShortToast(response.getMsg(), mContext);
                        }
                        // ((PQCAddActivity) mContext).showToast(response.getMsg());
                    }

                    @Override
                    public void onError(Throwable e, int id) {

                    }
                });
            }
        }

    }
    /**
     * @author ljp
     * @time 16:10
     * @describe 提交成功后清空原始数据
     */
    private void clearAddData() {
        // tvInspectionType.setText("");
        tvProductionStage.setText("");
        tvProcess.setText("");
        etDeviceId.setText("");
        tvDeviceName.setText("");
        tvItemName.setText("");
        etItemNum.setText("");
        etWorkInProgressBatch.setText("");
        etDisqualified.setText("");
        tvProductNumber.setText("");
        tvTestResult.setText("");
        pqcDetailsBeanAdd = null;
        gzlbID = 0;
        setPqcBean(null);
        PQCTestFragment2.getInstance().clearOldData();
    }
    /**
     * @author ljp
     * @time 13:57
     * @describe 检验项页面传过来的检验结果
     */
    public void setJson(String json, boolean isQualified) {
        testJson = json;
        if (FEATURES == 1) {
            tvTestResult.setText(isQualified ? "合格" : "不合格");
        } else {
            tvReviewResult.setText(isQualified ? "合格" : "不合格");
        }
    }

    int gzlbID = 0;//检查标识

    public void setPqcBean(PQCDetailsBean pqcDetailsBean) {
        this.pqcDetailsBeanTest = pqcDetailsBean;
    }

    public static PQCDetailsBean getPqcDetailsBeanTest() {
        return pqcDetailsBeanTest;
    }
    //在制品编码
    private String workResultCode;
    //载具编码
    private String resultCodeId;

    /**
     * @author ljp
     * @time 17:27
     * @describe 扫描二维码返回值
     */
    @Override
    public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        /**
         * 处理二维码扫描结果
         */
        if (requestCode == CODE_WORK_PROGRESS_BATCH) {
            //处理扫描结果（在界面上显示）
            if (null != data) {
                Bundle bundle = data.getExtras();
                if (bundle == null) {
                    return;
                }
                if (bundle.getInt(CodeUtils.RESULT_TYPE) == CodeUtils.RESULT_SUCCESS) {
                    workResultCode = bundle.getString(CodeUtils.RESULT_STRING);
                    //ToastUtil.showShortToast(workResultCode);
                    Log.i(TAG, "onActivityResult: ----扫描结果-----" + workResultCode);
                    etWorkInProgressBatch.setText(workResultCode);
                    etWorkInProgressBatch.setSelection(workResultCode.length());
                    codeHttpData(workResultCode,1);
                } else if (bundle.getInt(CodeUtils.RESULT_TYPE) == CodeUtils.RESULT_FAILED) {
                    ToastUtil.showShortToast("解析二维码失败", mContext);
                }
            }
        } else if (requestCode == CODE_MATERIAL_ID) {
            //处理扫描结果（在界面上显示）
            if (null != data) {
                Bundle bundle = data.getExtras();
                if (bundle == null) {
                    return;
                }
                if (bundle.getInt(CodeUtils.RESULT_TYPE) == CodeUtils.RESULT_SUCCESS) {
                    resultCodeId = bundle.getString(CodeUtils.RESULT_STRING);
                    // ToastUtil.showShortToast(result);
                    Log.i(TAG, "onActivityResult: ----扫描结果-----" + resultCodeId);
                    //etMaterialId.setText(resultCodeId);
                    codeHttpData(resultCodeId,2);
                } else if (bundle.getInt(CodeUtils.RESULT_TYPE) == CodeUtils.RESULT_FAILED) {
                    ToastUtil.showShortToast("解析二维码失败", mContext);
                }
            }
        }
    }

}
